package com.polimi.timer.business.weather.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.json.JSONObject;

public class JsonWeatherUtil {
	/**
	 * THESE METHODS PROVIDES TO GET VALUES FROM JSON OBJECT		
	 */
	public static Double getTemperature(JSONObject arg, byte modeFetch){
		if(modeFetch==5){
			Double temperature=(Double) arg.getJSONObject("main").get("temp");
			return temperature;
		}
		if(modeFetch==16){
			Double temperature=(Double) arg.getJSONObject("temp").get("eve");
			return temperature;		 
		}
		return null;
	}
	public static Date getTime(JSONObject arg) throws ParseException{	
		String timestamp=arg.getJSONArray("list").getJSONObject(0).getString("dt_txt");
		Date time =new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(timestamp);		 
		return time;
	}
	public static String getWeatherType(JSONObject arg, byte modeFetch){		
		return arg.getJSONArray("weather").getJSONObject(0).get("main").toString();		
	}	
	public static String getWeatherDescription(JSONObject arg, byte modeFetch){
		return arg.getJSONArray("weather").getJSONObject(0).get("description").toString();		
	}
	
	
}
